$(function(){
	real_name(1)
	$(".myfin_list .ordernav_item").on("click",function(){
		var i = $(this).index();
		//继承人资料屏蔽
		if(i != 2){
			$(this).addClass("on").siblings(".ordernav_item").removeClass("on");
			$(".page .page_list").eq(i).show().siblings(".page_list").hide();
		}
		var type = i + 1;
		//实名认证
		if(type === 1){
			real_name(type)
		//个人资料
		}else if(type === 2){
			var d={};
			d.type=type;
			d.token=token;
			$.ajax({
				type:"post",
				url:url+'/user/personinfo.html?token='+token,
				async:false,
				data:d,
				dataType:'json',
				success:function(result){
					// console.log(result)
					if(result.status === "0001"){
						var data=result.data;
						$(".username").html(data.username);
						$(".created_at").html(data.created_at);
						$(".inviter").html(data.inviter);
						
						if(data.btb_url == ""){
							$("#btb_url").attr("href","my_information_wallet.html");
							$(".btb_url").html('未绑定');
						}else{
							$(".btb_url").html(data.btb_url);
						}
						if(data.eth_url == ""){
							$("#eth_url").attr("href","my_information_wallet2.html");
							$(".eth_url").html('未绑定');
						}else{
							$(".eth_url").html(data.eth_url);
						}
						
		//	        	银行卡
						if(data.bank_number != ""){
							$(".bank_div").css("display","block");
							var banumber=data.bank_number;
							var idbanumber=banumber.replace(/^(.{4})(?:\d+)(.{4})$/,"$1******$2");
							$(".bank_number").html(idbanumber);
							$(".bank_name").html(data.bank_name);
						}
					}else{
						isErr(result);
					}
				},
				error:function(){
					layer.msg("响应失败");
				}
			})
		//继承人资料
		}else{
			var d={};
			d.type=type;
			d.token=token;
			$.ajax({
				type:"post",
				url:url+'/user/personinfo.html?token='+token,
				async:false,
				data:d,
				dataType:'json',
				success:function(result){
					if(result.status === "0001"){
						
					}else{
						isErr(result);
					}
				},
				error:function(){
					layer.msg("响应失败");
				}
			})
		}
	})

	//	提交实名认证
	var prevent_repetition=true;
	$(".authentication_btn").on("click",function(){
		if(prevent_repetition){
			prevent_repetition=false;
			var phoneNo=$(".phoneNo").val();
    		var name=$(".name").val();
    		var idNo=$(".idNo").val();
    		var cardNo=$(".cardNo").val();
			if(!phoneNo){
				layer.msg("请输入手机号码");
				prevent_repetition=true;
				return false;
			}
			if(!name){
				layer.msg("请输入真实姓名");
				prevent_repetition=true;
				return false;
			}
			if(!idNo){
				layer.msg("请输入身份证号码");
				prevent_repetition=true;
				return false;
			}
			if(!cardNo){
				layer.msg("请输入银行卡号码");
				prevent_repetition=true;
				return false;
			}
			var d={};
			d.token=token;
			d.phoneNo=phoneNo;
			d.name=name;
			d.idNo=idNo;
			d.cardNo=cardNo;
			$.ajax({
			    type:"post",
			    url:url+'/profile/dorealname.html?token='+token,
			    async:false,
			    data:d,
			    dataType:'json',
			    success:function(result){
			        if(result.status == "0001"){
			        	layer.msg(result.message);
			        	location.href='../my.html';
			        }else{
			            isErr(result);
			        }
			    },
				error:function(){
					layer.msg("响应失败");
				},
				complete: function() {
					prevent_repetition = true;
				}
			})
		}
	})
})

//实名认证
function real_name(type){
	var d={};
	d.type=type;
	d.token=token;
	$.ajax({
		type:"post",
		url:url+'/user/personinfo.html?token='+token,
		async:false,
		data:d,
		dataType:'json',
		success:function(result){
			if(result.status === "0001"){
				var data=result.data;
				if(data.state == "1"){
					$(".state").html("已认证");
					$(".authentication_btn").css("display","none");
					$(".phoneNo").val(data.phone).attr("readonly","readonly");
					$(".name").val(data.truename).attr("readonly","readonly");
					var card=data.idcard
					var idNo=card.replace(/^(.{4})(?:\d+)(.{4})$/,"$1******$2");
					$(".idNo").val(idNo).attr("readonly","readonly");
					var carno=data.card_no
					var cardNo=carno.replace(/^(.{4})(?:\d+)(.{4})$/,"$1******$2");
					$(".cardNo").val(cardNo).attr("readonly","readonly");
				}else{
					$(".state").html("未认证");
				}
			}else{
				isErr(result);
			}
		},
		error:function(){
			layer.msg("响应失败");
		}
	})
}
